// component/backtorule/backtorule.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    isnavigator:{
      type:Boolean,
      value:false
    },
    iscsorderno:{
      type:Number,
      value:''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    detail:null
  },

  /**
   * 组件的方法列表
   */
  methods: {
     /*关闭*/
     onisTrue(e){
      let that = this;
      that.setData({
        isnavigator:false
      })
    },
    getPhoneNumber (e) {
      console.log(e)
      let that = this;
      let  token =  wx.getStorageSync('token')
      that.setData({
        isnavigator:false
      })
      if(e.detail.errMsg=='getPhoneNumber:ok'){
        wx.request({
          url: 'https://www.yulonging.com/dwweb/wxapi.ashx',
          data: {
           //请求后台的分页数据
            cmd:'getPhoneNumber',
            encryptedData:e.detail.encryptedData,
            iv:e.detail.iv,
            token : token
          },
          method: "get",
          success(res) {
              console.log(res)
              if(res.data.STATUS=='Success'){
            //判断手机号获取成功继续绑定手机号 
                wx.request({
                  url: 'https://www.yulonging.com/dwweb/wxapi.ashx',
                  data: {
                   //请求后台的分页数据
                    cmd:'BindWxMobile',
                    mobile:res.data.DATA.PhoneNumber,
                    token : token
                  },
                  method: "get",
                  success(data) {
                    if(data.data.STATUS=='Success'){
                      wx.showToast({
                        title: '绑定成功',
                        icon: 'success',
                        duration: 1000
                      })
                      //刷新缓存
                      wx.login({
                        success (res) {
                          wx.getUserInfo({
                            success: function(b) {
                              wx.setStorageSync('wxinfo',b.userInfo);
                              wx.request({
                                url: 'https://www.yulonging.com/dwweb/wxapi.ashx',
                                data: {
                                  code: res.code,
                                  cmd: 'wxlogin',
                                  officeid:1
                                },
                                header: {
                                  'content-type': 'application/json' // 默认值
                                },
                                success (data) {
                                  if(data.STATUS='Success'){
                                    wx.setStorageSync('userInfo',data.data.DATA);
                                    wx.setStorageSync('token',data.data.DATA.token);
                                  }
                                }
                              });
                            }
                          })
                        }
                      })


                    }else{
                      wx.showToast({
                        title: '绑定失败',
                        icon: 'error',
                        duration: 1000
                      })
                    }
                  }})
              }
            }
        })
      }else{
        wx.showToast({
          title: '取消后部分功能将无法使用',
          icon: 'error',
          duration: 1000
        })
      }  
    },

    
  }
})
